﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;
using YiSha.Entity.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Service.QixingManage;
using YiSha.Model.Result.QixingManage;

namespace YiSha.Business.QixingManage
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2024-09-17 22:40
    /// 描 述：业务类
    /// </summary>
    public class StoreOrderDetailBLL
    {
        private StoreOrderDetailService storeOrderDetailService = new StoreOrderDetailService();

        #region 获取数据
        public async Task<TData<List<StoreOrderDetailEntity>>> GetList(StoreOrderDetailListParam param)
        {
            TData<List<StoreOrderDetailEntity>> obj = new TData<List<StoreOrderDetailEntity>>();
            obj.Data = await storeOrderDetailService.GetList(param);
            obj.Total = obj.Data.Count;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<StoreOrderDetailEntity>>> GetPageList(StoreOrderDetailListParam param, Pagination pagination)
        {
            TData<List<StoreOrderDetailEntity>> obj = new TData<List<StoreOrderDetailEntity>>();
            obj.Data = await storeOrderDetailService.GetPageList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<StoreOrderDetailEntity>> GetEntity(long id)
        {
            TData<StoreOrderDetailEntity> obj = new TData<StoreOrderDetailEntity>();
            obj.Data = await storeOrderDetailService.GetEntity(id);
            if (obj.Data != null)
            {
                obj.Tag = 1;
            }
            return obj;
        }

        public async Task<TData<List<OrderDetailDto>>> GetPageDetailList(OrderDetailListParam param, Pagination pagination)
        {
            TData<List<OrderDetailDto>> obj = new TData<List<OrderDetailDto>>();
            obj.Data = await storeOrderDetailService.GetPageDetailList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }
        public async Task<TData<List<OrderDetailDto>>> GetPageColourDetailList(OrderDetailListParam param, Pagination pagination)
        {
            TData<List<OrderDetailDto>> obj = new TData<List<OrderDetailDto>>();
            obj.Data = await storeOrderDetailService.GetPageColourDetailList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<string>> OrderDetailSaveFormJson(StoreOrderDetailEntity entity)
        {
            TData<string> obj = new TData<string>();
            var data = await storeOrderDetailService.GetEntity(entity.Id.Value);
            if (data != null)
            {
                data.productids = entity.productids;
                long[] idArr = TextHelper.SplitToArray<long>(entity.productids, ',');
                if (idArr.Length > 0)
                {
                    data.pw_id = idArr[0];
                }
                await storeOrderDetailService.OrderDetailSaveFormJson(data);
            }
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 提交数据
        public async Task<TData<string>> SaveForm(StoreOrderDetailEntity entity)
        {
            TData<string> obj = new TData<string>();
            await storeOrderDetailService.SaveForm(entity);
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData> DeleteForm(string ids)
        {
            TData obj = new TData();
            await storeOrderDetailService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 私有方法
        #endregion
    }
}
